package com.kitwee.serialport.instruction;


import android.os.Parcel;
import android.os.Parcelable;

import com.kitwee.serialport.decoder.InstructionDecoder;

public class Instruction implements Parcelable {

    private String key; // 指令名称
    private String value; // 十六进制字符串

    private Class<? extends InstructionDecoder> decoder = null; // 解码器

    @Deprecated
    public Instruction(String key, String value) {
        this.key = key;
        this.value = value;
    }

    public Instruction(String key, String value, Class<? extends InstructionDecoder> decoder) {
        this.key = key;
        this.value = value;
        this.decoder = decoder;
    }

    @SuppressWarnings("unchecked")
    protected Instruction(Parcel in) {
        key = in.readString();
        value = in.readString();
        decoder = (Class<? extends InstructionDecoder>) in.readSerializable();
    }

    public static final Creator<Instruction> CREATOR = new Creator<Instruction>() {
        @Override
        public Instruction createFromParcel(Parcel in) {
            return new Instruction(in);
        }

        @Override
        public Instruction[] newArray(int size) {
            return new Instruction[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(key);
        dest.writeString(value);
        dest.writeSerializable(decoder);
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public Class<? extends InstructionDecoder> getDecoder() {
        return decoder;
    }
}
